/*
 * 文件名：AlarmRepairController.java
 * 版权：Copyright by www.tiansu-china.com/
 * 描述：
 * 修改人：congriran
 * 修改时间：2020年12月17日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
*/
 
package com.tiansu.reborn.wanda.modules.executor.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tiansu.reborn.wanda.modules.executor.entity.AlarmDataEntity;
import com.tiansu.reborn.wanda.modules.executor.entity.AlarmTypeEntity;
import com.tiansu.reborn.wanda.modules.executor.entity.FacadeResponse;
import com.tiansu.reborn.wanda.modules.executor.entity.vo.AlarmRepairCondVO;
import com.tiansu.reborn.wanda.modules.executor.service.AlarmRepairService;

import lombok.extern.slf4j.Slf4j;

@Controller
@Slf4j
public class AlarmRepairController
{

    @Autowired
    private AlarmRepairService alarmRepairService;
    
    @GetMapping("/alarm_repair")
    public String index()
    {
        return "alarm_repair";
    }
    
    @ResponseBody
    @PostMapping("/getAlarmTypeList")
    public List<AlarmTypeEntity> getAlarmTypeList()
    {
        List<AlarmTypeEntity> data = alarmRepairService.getAlarmTypeList();
        return data;
    }
    
    @ResponseBody
    @PostMapping("/getAlarmList")
    public FacadeResponse getAlarmList(@RequestBody AlarmRepairCondVO vo)
    {
        FacadeResponse response = null;
        try
        {
            List<AlarmDataEntity> data = alarmRepairService.queryAlarmDataList(vo);
            response = FacadeResponse.ok();
            response.setData(data);
        }
        catch (Exception e)
        {
            response = FacadeResponse.error(e.getMessage());
            log.error("GetAlarmList error, error message is: " + e.getMessage());
        }
        return response;
    }
    
    @ResponseBody
    @PostMapping("/repairAlarm")
    public FacadeResponse repairAlarm(String alarmId)
    {
        FacadeResponse response = null;
        try
        {
            List<String> alarmIds = new ArrayList<String>();
            alarmIds.add(alarmId);
            Integer num = alarmRepairService.repairAlarm(alarmIds);
            response = FacadeResponse.ok("成功修复了" + num + "条告警。");
        }
        catch (Exception e)
        {
            response = FacadeResponse.error(e.getMessage());
            log.error("RepairAlarm error, error message is: " + e.getMessage());
        }
        return response;
    }
    
    @ResponseBody
    @PostMapping("/batchRepairAlarm")
    public FacadeResponse batchRepairAlarm(@RequestBody List<String> alarmIds)
    {
        FacadeResponse response = null;
        try
        {
            Integer num = alarmRepairService.repairAlarm(alarmIds);
            response = FacadeResponse.ok("成功修复了" + num + "条告警。");
        }
        catch (Exception e)
        {
            response = FacadeResponse.error(e.getMessage());
            log.error("BatchRepairRepair error, error message is: " + e.getMessage());
        }
        return response;
    }
    
}
